<div id="topRightBar">
    {% for label,menu in topMenu %}
        {% if menu._html is defined %}
            {{ menu._html|raw }}
        {% elseif (menu._url.module == currentModule and (menu._url.action is empty or menu._url.action == currentAction)) %}
            <span class="topBarElem topBarElemActive"><strong>{{ label|translate }}</strong></span>
        {% else %}
            <span class="topBarElem" {% if menu._tooltip is defined %}title="{{ menu._tooltip }}"{% endif %}>
                <a id="topmenu-{{ menu._url.module|lower }}" href="index.php{{ menu._url|urlRewriteWithParameters }}">{{ label|translate }}</a>
            </span>
        {% endif %}
        |
    {% endfor %}

    {% set helloAlias %}
    {% if userAlias is not empty %}
        {{ userAlias|raw }}
    {% else %}
        {{ userLogin|raw }}
    {% endif %}
    {% endset %}

    {% macro userMenuItem(label, menu, currentModule, currentAction) %}

        <a class="item {% if (menu._url.module == currentModule and (menu._url.action is empty or menu._url.action == currentAction)) %}active{% endif %}"
           href="index.php{{ menu._url|urlRewriteWithParameters }}"
           id="usermenu-{{ menu._url.module|lower }}-{{ menu._url.action|default('index')|lower }}"
           {% if menu._tooltip is defined %}title="{{ menu._tooltip }}"{% endif %}
                >{{ label|translate }}</a>

    {% endmacro %}

    <span class="topBarElem">
        <div id="userMenu"
             tooltip="{{ 'General_HelloUser'|translate(helloAlias|trim)|rawSafeDecoded }}"
             menu-title="{{ helloAlias|trim }}"
             piwik-menudropdown>

            {% for lev1UserLabel,lev1UserMenu in userMenu if lev1UserLabel|slice(0,1) != '_' %}
                {% if not loop.first %}
                    <hr class="item separator"/>
                {% endif %}

                {% if lev1UserMenu._hasSubmenu is defined and lev1UserMenu._hasSubmenu %}
                    {% if lev1UserLabel %}
                        <a class="item disabled category">{{ lev1UserLabel|translate }}</a>
                    {% endif %}

                    {% for lev2Label,lev2Menu in lev1UserMenu if lev2Label|slice(0,1) != '_' %}
                        {{ _self.userMenuItem(lev2Label, lev2Menu, currentModule, currentAction) }}
                    {% endfor %}
                {% else %}
                    {{ _self.userMenuItem(lev1UserLabel, lev1UserMenu, currentModule, currentAction) }}
                {% endif %}

            {% endfor %}
        </div>
    </span>

    | <span class="topBarElem">
        {% if userLogin == 'anonymous' %}
            <a href='index.php?module={{ loginModule }}'>{{ 'Login_LogIn'|translate }}</a>
        {% else %}
            <a href='index.php?module={{ loginModule }}&amp;action=logout'>{{ 'General_Logout'|translate }}</a>
        {% endif %}
    </span>
</div>
